package com.aplink.generic.pojo.googlemaps;

import java.lang.reflect.Type;

import com.aplink.generic.constant.type.TravelMode;
import com.google.android.gms.maps.model.LatLng;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;

public class DirectionsStep implements JsonDeserializer<DirectionsStep> {
	private Distance mDistance;
	private Duration mDuration;
	private LatLng mEndLocation;
	private String mInstructions;
	private String mPolyline;

	private LatLng mStartLocation;
	private TravelMode mTravelMode;

	@Override
	public DirectionsStep deserialize(JsonElement jsonElement, Type type,
	        JsonDeserializationContext context) throws JsonParseException {
		JsonObject jsonObject = jsonElement.getAsJsonObject();
		mDistance = context.deserialize(jsonObject.get("distance"),
		        Distance.class);
		mDuration = context.deserialize(jsonObject.get("duration"),
		        Duration.class);
		mInstructions = jsonObject.get("html_instructions").getAsString();
		mPolyline = jsonObject.get("polyline").getAsJsonObject().get("points")
		        .getAsString();
		mTravelMode = TravelMode.get(jsonObject.get("travel_mode")
		        .getAsString());
		JsonObject location = jsonObject.get("start_location")
		        .getAsJsonObject();
		mStartLocation = new LatLng(location.get("lat").getAsDouble(), location
		        .get("lng").getAsDouble());

		location = jsonObject.get("end_location").getAsJsonObject();
		mEndLocation = new LatLng(location.get("lat").getAsDouble(), location
		        .get("lng").getAsDouble());
		return this;
	}

	public Distance getDistance() {
		return mDistance;
	}

	public Duration getDuration() {
		return mDuration;
	}

	public LatLng getEndLocation() {
		return mEndLocation;
	}

	public String getInstructions() {
		return mInstructions;
	}

	public String getPolyline() {
		return mPolyline;
	}

	public LatLng getStartLocation() {
		return mStartLocation;
	}

	public TravelMode getTravelMode() {
		return mTravelMode;
	}

	public void setDistance(Distance distance) {
		mDistance = distance;
	}

	public void setDuration(Duration duration) {
		mDuration = duration;
	}

	public void setEndLocation(LatLng endLocation) {
		mEndLocation = endLocation;
	}

	public void setInstructions(String instructions) {
		mInstructions = instructions;
	}

	public void setPolyline(String polyline) {
		mPolyline = polyline;
	}

	public void setStartLocation(LatLng startLocation) {
		mStartLocation = startLocation;
	}

	public void setTravelMode(TravelMode travelMode) {
		mTravelMode = travelMode;
	}

}
